
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_app_05/action/states/dark_states.dart';
import 'package:flutter_app_05/action/states/data_manager.dart';
import 'package:flutter_app_05/data/model.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:provider/provider.dart';


class Padecalthree extends StatefulWidget{
  @override
  _PadecalthreeInState createState() => _PadecalthreeInState();

}

class _PadecalthreeInState extends State<Padecalthree>{
  var _dropValue = null;
  List<ZuliItem> zuliList;
  List<DropdownMenuItem> list=[];
  String htmls="<p/>";
  TextEditingController areaController=new TextEditingController();
  TextEditingController lenController=new TextEditingController();
  TextEditingController flowController=new TextEditingController();
  @override
  Widget build(BuildContext context) {
    return Consumer<DartState>(builder: (context, categoryState, child) {
      return columns(categoryState);
    });
  }
  Widget columns(DartState categoryState) {
    Widget h=Container(height: 1,color: MyTheme(context).getColor("line_color"),alignment: Alignment.center,margin: EdgeInsets.only(top: 10.0,bottom: 10.0),);
    Widget z=Container(height: 1,color:MyTheme(context).getColor("line_color"),alignment: Alignment.center,margin: EdgeInsets.only(top: 0,bottom: 10),);
    return Container(
      color: MyTheme(context).getColor("bg"),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.all(10.0),
            padding: EdgeInsets.all(15),
            decoration: new BoxDecoration(
                color: MyTheme(context).getColor("white"),
                borderRadius: new BorderRadius.circular((10.0))),
            alignment: Alignment.center,
            height: 270,
            child: Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text("*",style: TextStyle(color: Colors.red),),
                    Expanded(child:  Text("供暖面积",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        style: TextStyle(color: Colors.green),
                        maxLength: 100,
                        controller: areaController,
                        decoration: null,
                      ),
                    ),
                    Text("m²",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Expanded(child:  Text("  预供流量",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        style: TextStyle(color: MyTheme(context).getColor('colorBlack')),
                        controller: flowController,
                        maxLength: 100,
                        decoration: null,
                      ),
                    ),
                    Text("L/m²",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),),
                  ],
                ),
                h,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Container(
                        width: 100,
                        height:40,

                        child: FlatButton(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.all(Radius.circular(80.0)),
                      ),
                      child: Text(
                        '提交',
                        style: TextStyle(color: Colors.white,fontSize: 15),
                      ),
                      color: Colors.green,
                      onPressed: () {
                        info01();

                        setState(() {
                        });
                      },
                    )),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text("*",style: TextStyle(color: Colors.red),),
                    Expanded(child:  Text("比摩阻",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                   _dropValue==null? Container(
                      decoration: new BoxDecoration(
                        // border: new Border.all(color: Color(0xFFFF0000), width: 0.5),
                          borderRadius: new BorderRadius.circular((10.0))),
                      width: 140.0,
                      height: 40,

                    ):Container(
                     decoration: new BoxDecoration(
                       // border: new Border.all(color: Color(0xFFFF0000), width: 0.5),
                         borderRadius: new BorderRadius.circular((10.0))),
                     width: 140.0,
                     height: 40,
                     child:DropdownButtonHideUnderline(
                       child:DropdownButton(
                         value: _dropValue,
                         items:list,

                         onChanged: (value){
                           setState(() {
                             _dropValue = value;
                           });
                         },
                       ),
                     ),
                   ),
                    Container(
                      decoration: new BoxDecoration(
                          borderRadius: new BorderRadius.circular((10.0))),
                      child:  Text(
                          "Pa/m",
                        style: TextStyle(color: MyTheme(context).getColor('colorBlack')),
                      ),
                    ),
                  ],
                ),
                z,
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text("*",style: TextStyle(color: Colors.red),),
                    Expanded(child:  Text("长度",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),)),
                    Container(
                      width: 100.0,
                      child: TextField(
                        textAlign: TextAlign.right,
                        style: TextStyle(color: MyTheme(context).getColor('colorBlack')),
                        maxLength: 100,
                        controller: lenController,
                        decoration: null,
                      ),
                    ),
                    Text("m",style: TextStyle(color: MyTheme(context).getColor('colorBlack')),),
                  ],
                ),
                h,
              ],
            ),
          ),
          Center(child: Html(

              data :htmls,),

          ),
          Expanded(
              child: Stack(
                children: [
                  Positioned(
                    child: Container(
                      height: 60.0,

                      alignment: Alignment.bottomCenter,
                      child: Row(
                        children: [
                          Expanded(
                            child: GestureDetector(
                              child: Container(
                                color: MyTheme(context).getColor("white"),
                                child: Center(
                                  child: Text(
                                    "重置",
                                    style: new TextStyle(fontSize: 25.0,color: MyTheme(context).getColor('text_color')),
                                  ),
                                ),
                              ),
                              onTap: () {
                                lenController.text="";
                                flowController.text="";
                                areaController.text="";
                              },
                            ),
                          ),
                          Expanded(
                            child: GestureDetector(
                              child:   Container(
                                color: Colors.green,

                                child: Center(
                                  child: Text(
                                    "提交",
                                    style: new TextStyle(fontSize: 25.0,color: Colors.white),
                                  ),
                                ),
                              ),
                              onTap: (){
                                info02();
                                htmls="请先设置比萨摩";
                                setState(() {

                                });
                              },
                            ),
                          )
                        ],
                      ),
                    ),
                    bottom: 0,
                    left: 0,
                    right: 0,
                  ),
                ],
              )),

        ],
      ),
    );
  }


  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  List<DropdownMenuItem> initList(){
    list.clear();
    for(int i=0;i<zuliList.length;i++){
      DropdownMenuItem a= DropdownMenuItem(child: Text(zuliList[i].item,style: TextStyle(color: Colors.green)),value:zuliList[i].item);
      list.add(a);
    }
    _dropValue=zuliList[0].item;
    return list;

  }


  void  info01()async{
    var a=await DataManager.getBmz(p: {"area":areaController.text,"flow":flowController.text,"size":"0","coefficient":"1","from":"iOS"}).then((value) {
      zuliList=value.data;

      setState(() {
        initList();
      });
    });

  }
  void  info02()async{

    if(_dropValue==null){
      return;
    }
    var a=await DataManager.getZl(p: {"rmod":_dropValue,"len":lenController.text,"size":"0","coefficient":"1","from":"iOS"}).then((value) {
      htmls=value.data;
      setState(() {
      });
    });

  }
}